package com.zhy.sunmi.myView;

import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.widget.Button;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.sunmi.R;
import com.zhy.sunmi.bean.SellingGood;
import com.zhy.sunmi.bean.SoldGoodDetail;
import com.zhy.sunmi.fragment.sell.SubSellingFragment;
import com.zhy.sunmi.utils.XMathUtil;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouhongyang
 */
public class MyPresentation extends Presentation {

    private RecyclerView recyclerView;
    private List<SoldGoodDetail> soldGoodDetailList = new ArrayList<>();
    private Button bt_return;
    public MyPresentation(Context outerContext, Display display) {
        super(outerContext, display);
    }

    public MyPresentation(Context outerContext, Display display, int theme) {
        super(outerContext, display, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_display);
        initView();
    }


    private void initView() {
        recyclerView=findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(new CommonAdapter<SoldGoodDetail>(getContext(),R.layout.item_selling_good,soldGoodDetailList) {

            @Override
            protected void convert(ViewHolder holder, SoldGoodDetail sellingGood, int position) {
                holder.setText(R.id.selling_number, sellingGood.getNumber() + "");
                holder.setVisible(R.id.iv_ljt, false);
                holder.setText(R.id.tv_good_disoff, new Double(sellingGood.getDiscount()).intValue() + "%");
                holder.setText(R.id.tv_selling_money, "£" + new BigDecimal(sellingGood.getTotalPrice()).setScale(2, BigDecimal.ROUND_DOWN).toString());
                holder.setText(R.id.tv_goodname, sellingGood.getEnglishName());
                holder.setText(R.id.tv_goodCname, sellingGood.getChineseName());
            }
        });

    }


    public void setData(List<SoldGoodDetail> soldGoodDetails){
        soldGoodDetailList.clear();
        soldGoodDetailList.addAll(soldGoodDetails);
        recyclerView.getAdapter().notifyDataSetChanged();
    }
}
